
Public Class frmAddGroundChit
    Inherits System.Windows.Forms.Form

    Const OBJECTIVE_RULEINDEX = 9

    Private ptrItem As cmplib01.GroundChitType  ' this is the new item
    Private ptrCGD As cmplib01.CampaignerGameData  ' provided so we can show the rules and resources 
    Private mMode As OpenMode = OpenMode.ObjectiveType
    Private objectiveItemIndex = OBJECTIVE_RULEINDEX
    Private moveTypes() As String

    Private mvarCancelled As Boolean = False

    Public Enum OpenMode
        ObjectiveType = 1
        UnitType = 2
        TokenType = 3
    End Enum

    Private Enum ItemListIndex
        Description = 0
        [Name] = 1
        TypeName = 2
        LOS = 3
        LOSPower = 4
        Size = 5
        UsesZOC = 6
        ZOCRange = 7
        Icons = 8
        ObjectiveRules = 9       ' objective type only
        MovementClass = 9     ' token and unit only
        MoveSpeed = 10          ' token and unit only
        TokenRule = 11            ' token only
    End Enum

#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    Friend WithEvents chdProperty As System.Windows.Forms.ColumnHeader
    Friend WithEvents chdValue As System.Windows.Forms.ColumnHeader
    Friend WithEvents btnOK As System.Windows.Forms.Button
    Friend WithEvents lvwProperties As System.Windows.Forms.ListView
    Friend WithEvents btnCancel As System.Windows.Forms.Button
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Dim ListViewItem1 As System.Windows.Forms.ListViewItem = New System.Windows.Forms.ListViewItem(New System.Windows.Forms.ListViewItem.ListViewSubItem() {New System.Windows.Forms.ListViewItem.ListViewSubItem(Nothing, "Description", System.Drawing.SystemColors.ControlText, System.Drawing.SystemColors.Window, New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))), New System.Windows.Forms.ListViewItem.ListViewSubItem(Nothing, "[None]")}, -1)
        Dim ListViewItem2 As System.Windows.Forms.ListViewItem = New System.Windows.Forms.ListViewItem(New System.Windows.Forms.ListViewItem.ListViewSubItem() {New System.Windows.Forms.ListViewItem.ListViewSubItem(Nothing, "Name", System.Drawing.SystemColors.ControlText, System.Drawing.SystemColors.Window, New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))), New System.Windows.Forms.ListViewItem.ListViewSubItem(Nothing, "[None]")}, -1)
        Dim ListViewItem3 As System.Windows.Forms.ListViewItem = New System.Windows.Forms.ListViewItem(New System.Windows.Forms.ListViewItem.ListViewSubItem() {New System.Windows.Forms.ListViewItem.ListViewSubItem(Nothing, "Type Name", System.Drawing.SystemColors.ControlText, System.Drawing.SystemColors.Window, New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))), New System.Windows.Forms.ListViewItem.ListViewSubItem(Nothing, "[None]")}, -1)
        Dim ListViewItem4 As System.Windows.Forms.ListViewItem = New System.Windows.Forms.ListViewItem(New System.Windows.Forms.ListViewItem.ListViewSubItem() {New System.Windows.Forms.ListViewItem.ListViewSubItem(Nothing, "Line Of Sight", System.Drawing.SystemColors.ControlText, System.Drawing.SystemColors.Window, New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))), New System.Windows.Forms.ListViewItem.ListViewSubItem(Nothing, "0")}, -1)
        Dim ListViewItem5 As System.Windows.Forms.ListViewItem = New System.Windows.Forms.ListViewItem(New System.Windows.Forms.ListViewItem.ListViewSubItem() {New System.Windows.Forms.ListViewItem.ListViewSubItem(Nothing, "LOS Power", System.Drawing.SystemColors.ControlText, System.Drawing.SystemColors.Window, New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))), New System.Windows.Forms.ListViewItem.ListViewSubItem(Nothing, "0")}, -1)
        Dim ListViewItem6 As System.Windows.Forms.ListViewItem = New System.Windows.Forms.ListViewItem(New System.Windows.Forms.ListViewItem.ListViewSubItem() {New System.Windows.Forms.ListViewItem.ListViewSubItem(Nothing, "Size", System.Drawing.SystemColors.ControlText, System.Drawing.SystemColors.Window, New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))), New System.Windows.Forms.ListViewItem.ListViewSubItem(Nothing, "10")}, -1)
        Dim ListViewItem7 As System.Windows.Forms.ListViewItem = New System.Windows.Forms.ListViewItem(New System.Windows.Forms.ListViewItem.ListViewSubItem() {New System.Windows.Forms.ListViewItem.ListViewSubItem(Nothing, "Uses Zone Of Control", System.Drawing.SystemColors.ControlText, System.Drawing.SystemColors.Window, New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))), New System.Windows.Forms.ListViewItem.ListViewSubItem(Nothing, "No")}, -1)
        Dim ListViewItem8 As System.Windows.Forms.ListViewItem = New System.Windows.Forms.ListViewItem(New System.Windows.Forms.ListViewItem.ListViewSubItem() {New System.Windows.Forms.ListViewItem.ListViewSubItem(Nothing, "ZOC Range", System.Drawing.SystemColors.ControlText, System.Drawing.SystemColors.Window, New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))), New System.Windows.Forms.ListViewItem.ListViewSubItem(Nothing, "0")}, -1)
        Dim ListViewItem9 As System.Windows.Forms.ListViewItem = New System.Windows.Forms.ListViewItem(New System.Windows.Forms.ListViewItem.ListViewSubItem() {New System.Windows.Forms.ListViewItem.ListViewSubItem(Nothing, "Icons", System.Drawing.SystemColors.ControlText, System.Drawing.SystemColors.Window, New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))), New System.Windows.Forms.ListViewItem.ListViewSubItem(Nothing, "[Edit]")}, -1)
        Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(frmAddGroundChit))
        Me.lvwProperties = New System.Windows.Forms.ListView()
        Me.chdProperty = New System.Windows.Forms.ColumnHeader()
        Me.chdValue = New System.Windows.Forms.ColumnHeader()
        Me.btnOK = New System.Windows.Forms.Button()
        Me.btnCancel = New System.Windows.Forms.Button()
        Me.SuspendLayout()
        '
        'lvwProperties
        '
        Me.lvwProperties.Columns.AddRange(New System.Windows.Forms.ColumnHeader() {Me.chdProperty, Me.chdValue})
        Me.lvwProperties.ForeColor = System.Drawing.SystemColors.ControlText
        Me.lvwProperties.GridLines = True
        Me.lvwProperties.Items.AddRange(New System.Windows.Forms.ListViewItem() {ListViewItem1, ListViewItem2, ListViewItem3, ListViewItem4, ListViewItem5, ListViewItem6, ListViewItem7, ListViewItem8, ListViewItem9})
        Me.lvwProperties.Location = New System.Drawing.Point(8, 64)
        Me.lvwProperties.Name = "lvwProperties"
        Me.lvwProperties.Size = New System.Drawing.Size(224, 302)
        Me.lvwProperties.TabIndex = 0
        Me.lvwProperties.View = System.Windows.Forms.View.Details
        '
        'chdProperty
        '
        Me.chdProperty.Text = "Property"
        Me.chdProperty.Width = 114
        '
        'chdValue
        '
        Me.chdValue.Text = "Value"
        Me.chdValue.Width = 89
        '
        'btnOK
        '
        Me.btnOK.Anchor = (System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Right)
        Me.btnOK.Location = New System.Drawing.Point(80, 376)
        Me.btnOK.Name = "btnOK"
        Me.btnOK.TabIndex = 1
        Me.btnOK.Text = "OK"
        '
        'btnCancel
        '
        Me.btnCancel.Anchor = (System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Right)
        Me.btnCancel.Location = New System.Drawing.Point(160, 376)
        Me.btnCancel.Name = "btnCancel"
        Me.btnCancel.TabIndex = 2
        Me.btnCancel.Text = "Cancel"
        '
        'frmAddGroundChit
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(242, 408)
        Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.btnCancel, Me.btnOK, Me.lvwProperties})
        Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle
        Me.Icon = CType(resources.GetObject("$this.Icon"), System.Drawing.Icon)
        Me.MaximizeBox = False
        Me.MinimizeBox = False
        Me.Name = "frmAddGroundChit"
        Me.Text = "Chit Properties"
        Me.ResumeLayout(False)

    End Sub

#End Region

    Public Sub New(ByVal openM As OpenMode, ByRef CGD As cmplib01.CampaignerGameData, ByRef Item As cmplib01.GroundChitType, ByVal MovementTypes() As String)
        InitializeComponent()

        ' we need the movementtypes (infantry, wheeled, etc) for movement class information
        moveTypes = MovementTypes

        ' set the pointer to the locally used variable and the mode, then populate
        ptrCGD = CGD
        ptrItem = Item
        mMode = openM

        Populate()

    End Sub

    Public Sub Populate()
        Try
            Me.lvwProperties.Items.Clear()
        Catch
            Debug.WriteLine("!!Error in frmAddGroundChit.Populate")
        End Try

        objectiveItemIndex = OBJECTIVE_RULEINDEX    ' reset the index so the correct spot is modified
        ' base properties, common to all ground chits
        PopulateBaseProperties()

        ' add the type-specific properties here.
        Select Case mMode
            Case OpenMode.ObjectiveType : PopulateObjectiveType()
            Case OpenMode.UnitType : PopulateUnitType()
            Case OpenMode.TokenType : PopulateTokenType()
        End Select

    End Sub

    Public Sub PopulateBaseProperties()

        Dim comGround As cmplib01.GroundChitType
        comGround = CType(ptrItem, cmplib01.GroundChitType)

        ' show the basic data, common to all chits
        lvwProperties.Items.Add("Description")
        lvwProperties.Items(ItemListIndex.Description).SubItems.Add(comGround.Description)

        lvwProperties.Items.Add("Name")
        lvwProperties.Items(ItemListIndex.Name).SubItems.Add(comGround.Name)

        lvwProperties.Items.Add("Type Name")
        lvwProperties.Items(ItemListIndex.TypeName).SubItems.Add(comGround.TypeName)

        lvwProperties.Items.Add("LOS")
        lvwProperties.Items(ItemListIndex.LOS).SubItems.Add(comGround.LOS)

        lvwProperties.Items.Add("LOS Power")
        lvwProperties.Items(ItemListIndex.LOSPower).SubItems.Add(comGround.LOSPower)

        lvwProperties.Items.Add("Size")
        lvwProperties.Items(ItemListIndex.Size).SubItems.Add(comGround.Size)

        lvwProperties.Items.Add("Uses ZOC")
        If comGround.UsesZOC = True Then
            lvwProperties.Items(ItemListIndex.UsesZOC).SubItems.Add("Yes")
        Else
            lvwProperties.Items(ItemListIndex.UsesZOC).SubItems.Add("No")
        End If

        lvwProperties.Items.Add("ZOC Range")
        lvwProperties.Items(ItemListIndex.ZOCRange).SubItems.Add(comGround.ZOCRange)

        lvwProperties.Items.Add("Icons")
        lvwProperties.Items(ItemListIndex.Icons).SubItems.Add("[Edit]")

    End Sub

    Public Sub PopulateObjectiveType()
        ' add any rules that the objective exposes, followed by a "New Rule" entry
        Dim rul As cmplib01.Rule
        Dim key As String
        Dim objective As cmplib01.ObjectiveType
        Dim i As Int16

        ' for local use
        objective = ptrItem

        Dim de As DictionaryEntry

        ' populate the rules
        For Each de In objective.ObjectiveRules.HT
            key = de.Key
            rul = objective.ObjectiveRules.Item(key)
            lvwProperties.Items.Add("Rule")
            lvwProperties.Items(objectiveItemIndex).ForeColor = System.Drawing.Color.DarkBlue
            lvwProperties.Items(objectiveItemIndex).SubItems.Add(rul.ruleName)
            objectiveItemIndex += 1
        Next

        ' populate the resources this objective type generates
        Dim res As cmplib01.Resource

        For Each de In objective.ObjectiveResources.HT
            key = de.Key
            res = objective.ObjectiveResources.Item(key)
            lvwProperties.Items.Add("Resource")
            lvwProperties.Items(objectiveItemIndex).ForeColor = System.Drawing.Color.DarkGreen
            lvwProperties.Items(objectiveItemIndex).SubItems.Add(res.ResourceName)
            objectiveItemIndex += 1
        Next

    End Sub

    Public Sub PopulateUnitType()
        Dim mType As String
        Dim unit As cmplib01.UnitType

        unit = ptrItem

        mType = moveTypes(unit.MovementClassID)

        lvwProperties.Items.Add("Movement Class")
        lvwProperties.Items(ItemListIndex.MovementClass).SubItems.Add(mType)

        lvwProperties.Items.Add("Movement Speed")
        lvwProperties.Items(ItemListIndex.MoveSpeed).SubItems.Add(unit.MovementSpeed.ToString)

    End Sub

    Public Sub PopulateTokenType()
        ' it gets its info from UnitTypes, plus adds its own rule
        PopulateUnitType()

        Dim tok As cmplib01.TokenType
        Dim rul As cmplib01.Rule

        tok = ptrItem
        rul = tok.TokenRule

        Try
            lvwProperties.Items.Add("Rule")
            lvwProperties.Items(ItemListIndex.TokenRule).SubItems.Add(rul.ruleName)
        Catch
            lvwProperties.Items.Add("Add Rule")
            lvwProperties.Items(ItemListIndex.TokenRule).SubItems.Add("Add Rule")
        End Try

    End Sub

    Public ReadOnly Property Cancelled() As Boolean
        Get
            Return mvarCancelled
        End Get
    End Property

    Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click
        mvarCancelled = True
        Me.Hide()
    End Sub

    Private Sub btnOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click
        mvarCancelled = False
        Me.Hide()
    End Sub

    Private Sub frmAddGroundChit_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    End Sub

End Class
